home *** CD-ROM | disk | FTP | other *** search
/ BBS Toolkit / BBS Toolkit.iso / pc_board / hstreset.zip / HSTRESET.PAS < prev   
Pascal/Delphi Source File  |  1992-03-22  |  3KB  |  165 lines

  1.  
  2. (*
  3.  * HSTRESET - Reset the HST modem so PCBoard won't get in trouble...
  4.  *
  5.  * (C) 1988 Samuel H. Smith, 22-Feb-88 (rev. 22-Feb-88)
  6.  *
  7.  *)
  8.  
  9. (* ------------------------------------------------------------ *)
  10. {$v-}
  11.  
  12. uses dos,minicrt,tools,proroot,prodata;
  13.  
  14. const
  15.    whoami   = 'HST Modem Reset Utility - Places hayes compatible modems Off-Hook';
  16.    version  = 'Version 2.0, 03-22-92 S.H.Smith';
  17.  
  18.    reset_command = 'ATM0H1'^M;
  19.    initial_timeout = 3;
  20.    timeout = 3;
  21.    max_trys = 100;
  22.  
  23. var
  24.    linenum:  integer;
  25.    inbuf:    string;
  26.    lastln:   string;
  27.    try:      integer;
  28.  
  29.    procedure xmit(s: string);
  30.    var
  31.       i: integer;
  32.    begin
  33.       for i := 1 to length(s) do
  34.          INTR_transmit_data(s[i]);
  35.  
  36.       INTR_flush_com;
  37.    end;
  38.  
  39.  
  40.    procedure recv;
  41.    var
  42.       c:   char;
  43.    begin
  44.  
  45.       repeat
  46.          if INTR_receive_ready then
  47.             c := INTR_receive_data
  48.          else
  49.             c := #255;
  50.  
  51.          case c of
  52.             #255: exit;
  53.  
  54.             ' '..'~':
  55.                 inbuf := inbuf + c;
  56.             ^J:
  57.                 if length(inbuf) > 1 then
  58.                 begin
  59.                    lastln := inbuf;
  60.                    inbuf := '';
  61.                 end;
  62.          end;
  63.          write(c);
  64.       until true=false;
  65.  
  66.    end;
  67.  
  68.  
  69. (*
  70.  * main program
  71.  *
  72.  *)
  73.  
  74. var
  75.    c: char;
  76.    port: string;
  77.    time: real;
  78.  
  79.  
  80. begin
  81.    clrscr;
  82.    assign(output,'');
  83.    rewrite(output);
  84.  
  85.    writeln(whoami);
  86.    writeln(version);
  87.  
  88.    if paramcount <> 1 then
  89.    begin
  90.       writeln('Usage:    hstreset PORT');
  91.       writeln('Example:  hstreset 1    ;reset COM1');
  92.       writeln;
  93.       writeln('Use COMBASE and COMIRQ environment variables with PORT 1 ');
  94.       writeln('for non-standard COM ports.');
  95.       writeln;
  96.       halt;
  97.    end;
  98.  
  99. (* install interrupt handlers *)
  100.    local := false;
  101.    port := paramstr(1);
  102.    com_chan := ord(port[1])-ord('0');
  103.    INTR_init_com;
  104.    disable_cts_check := true;
  105.  
  106.    c := '?';
  107.    inbuf := '';
  108.    lastln := '<timeout>';
  109.    time := get_time-timeout+initial_timeout;
  110.    try := 1;
  111.  
  112.    writeln('Press ESCAPE to cancel modem reset and drop to DOS...');
  113.  
  114.    repeat
  115.       recv;
  116.  
  117.       if {(lastln = '') and} (get_time > time+timeout) then
  118.       begin
  119.          lastln := '<timeout>';
  120.          writeln(lastln);
  121.       end;
  122.  
  123.       if (lastln = '<timeout>') or
  124.          (lastln = 'RING') or
  125.          (lastln = 'NO CARRIER') or
  126.          (lastln = 'NO DIAL TONE') then
  127.       begin
  128.          inc(try);
  129.          if try > max_trys then
  130.          begin
  131.             writeln('<modem not responding> errorlevel set to 0');
  132.             INTR_uninit_com;
  133.             halt(0);
  134.          end;
  135.  
  136.          INTR_lower_dtr;
  137.          delay(200);
  138.          INTR_raise_dtr;
  139.          delay(200);
  140.          xmit(reset_command);
  141.          delay(500);
  142.  
  143.          lastln := '';
  144.          time := get_time;
  145.       end;
  146.  
  147.       if keypressed then
  148.       begin
  149.          c := readkey;
  150.          if c = #27 then
  151.          begin
  152.             writeln('<user abort> - errorlevel set to 0');
  153.             INTR_uninit_com;
  154.             halt(0);
  155.          end;
  156.       end;
  157.    until lastln = 'OK';
  158.  
  159. (* remove interrupt handlers before exit *)
  160.    writeln('<modem reset successful> - errorlevel set to 1');
  161.    INTR_uninit_com;
  162.    halt(1);
  163. end.
  164.  
  165.